import { Component } from '@angular/core';
import {OrderService} from "../../service/order.service";

@Component({
  selector: 'app-manager-order',
  templateUrl: './manager-order.component.html',
    styleUrls: ["../../../assets/css/manager/bootstrap.css",
        "../../../assets/css/manager/font-awesome.css",
        "../../../assets/css/manager/morris-0.4.3.min.css",
        "../../../assets/css/manager/custom-styles.css",
        "../../../assets/css/manager/google.css",
        "manager-order.component.css"
    ]
})
export class ManagerOrderComponent {
    orderVO: any;
    editing: string = "";
    inputOrderId: string = "";
    deleteOrder: string[] = [];

    constructor(private orderService: OrderService) {
    }

    searchOrderId() {
        // @ts-ignore
        if (this.inputOrderId == "" || this.inputOrderId == null) {
           this.orderService.getOrderVO().subscribe(orders => {
              this.orderVO = orders?.data;
           });
        } else {
            for (let orderInfo of this.orderVO?.orderInfoList) {
                if (!String(orderInfo.oderId).includes(this.inputOrderId+"")) {
                    this.deleteOrder.push(orderInfo.oderId);
                }
            }
        }
    }

    saveRow(id: string) {
        this.editing = "";
        this.orderService.updateOrderStatus(id, "P").subscribe(response => {
            if (response?.code == 200) {
                console.log("好");
                this.searchOrderId();
            }
        });
    }

    dropRow(id: string) {
        console.log(id);
        this.deleteOrder.push(id);
    }
}
